package org.lq.ssm.vo.mapper;

import org.lq.ssm.dto.UserDTO;
import org.lq.ssm.vo.UserVO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import org.mapstruct.factory.Mappers;

@Mapper
public interface UserVOMapper {

    UserVOMapper INSTANCE = Mappers.getMapper( UserVOMapper.class );

    @Mappings({
            @Mapping(source = "dept" ,target = "dept",ignore = true),
            @Mapping(source = "job" ,target = "job",ignore = true),
            @Mapping(source = "avatarId",target = "avatar")
    })
    UserVO userDTOToVO(UserDTO userDTO);

    default UserVO specialUserDTOToVO(UserDTO userDTO){
        UserVO userVO = userDTOToVO(userDTO);

        UserVO.UserDept userDept = new UserVO.UserDept();
        UserVO.UserJob userJob = new UserVO.UserJob();

        userDept.setId(userDTO.getDept().getPid());
        userDept.setName(userDTO.getDept().getName());
        userJob.setName(userDTO.getJob().getName());
        userJob.setId(userDTO.getJob().getId());

        userVO.setDept(userDept);
        userVO.setJob(userJob);
        return userVO;
    }
}
